/*
 * Basestation.cpp
 *
 *  Created on: 6 mei 2013
 *      Author: Wietse
 */

#include "Basestation.h"
#include "Swarm.h"

#include <iostream>

/**
 * Default constructor
 */
BaseStation::BaseStation()
{
	init();

	sourceType = BASESTATION;
	this->ID = 0;
	this->position = Position();
	this->output_timer = 0.0;
}

/**
 * Preferred constructor
 */
BaseStation::BaseStation(int ID, Position position)
{
	init();

	sourceType = BASESTATION;
	this->ID = ID;
	this->position = position;
	this->output_timer = 0.0;
}

/**
 * Default destructor
 */
BaseStation::~BaseStation()
{
}

/**
 * Update the BaseStation
 */
void BaseStation::update(Swarm *swarm, double deltaTime)
{
	// Receive messages
	receiveMessages(swarm);

	// Add the elapsed time since the last update to the timer
	output_timer += deltaTime;

	// Check if the timer has expired
	if(output_timer > QUADCOPTER_MESSAGESPEED)
	{
		// Print the received data
		if(DEBUG)
		{
			printData();
			printImage();
		}

		// Generate output to txt files
		if(OUTPUT)
		{
			outputData();
			outputImage();
		}

		// Reset the message timer
		output_timer = 0;
	}
}


/**
 * Draw the BaseStation on screen
 */
void BaseStation::display()
{
	// Draw BaseStation as a square
	glBegin(GL_QUADS);
	glVertex3f(position.getX()-BASESTATION_WIDTH/2, position.getZ()-BASESTATION_HEIGHT/2, 0.0);
	glVertex3f(position.getX()+BASESTATION_WIDTH/2, position.getZ()-BASESTATION_HEIGHT/2, 0.0);
	glVertex3f(position.getX()+BASESTATION_WIDTH/2, position.getZ()+BASESTATION_HEIGHT/2, 0.0);
	glVertex3f(position.getX()-BASESTATION_WIDTH/2, position.getZ()+BASESTATION_HEIGHT/2, 0.0);
	glEnd();
}

